//
//  WPGetToken.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/8.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPGetToken.h"
#import "AFNetworking.h"
#import "URL.h"

@implementation WPGetToken
+ (void)getTokenWithSuccessBlock:(void (^)(NSString *))success andWithFailureBlock:(void (^)(NSString *))failure {
    NSString * url = [BASIC_URL stringByAppendingString:@"wjs_platform/moveSoftware/index.jhtml"];
    NSLog(@"%@", url);
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:@{} success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        if (responseObject) {
            if (responseObject[@"returnType"] && [responseObject[@"returnType"] intValue] && responseObject[@"resultMsg"]) {
                [[NSUserDefaults standardUserDefaults]setObject:responseObject[@"resultMsg"] forKey:@"token"];
            } else {
                failure(responseObject[@"resultMsg"] ? responseObject[@"resultMsg"]:@"网络数据错误");
            }
        } else {
            failure(@"网络数据错误");
        }
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        NSLog(@"%@", error.localizedDescription);
    }];
//    [NetWorkingManager postWithUrl:@"wjs_platform/moveSoftware/index.jhtml" requestParams:@{} SuccessHandler:^(id responseObject) {
//        if (responseObject) {
//            
//        } else {
//            
//        }
//    } failureHandler:^(NSError *error) {
//        failure(error.localizedDescription);
//    }];
}
@end
